<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>fetchAJAX请求</title>

</head>

<body>
    <button>AJAX请求</button>
    <script>
        var btn = document.querySelector('button');
        btn.onclick = function () {
            fetch('http://localhost:8000/fetch', {
                method: 'post',
                body: 'username=admin&password=admin',
                headers: {
                    // 'name': 'fetch',
                    'Content-Type': 'application/x-www-form-urlencoded'
                }
            }).then((result) => {
                // console.log(result);
                return result.text();
            }).then((result) => {
                console.log(result);
            }).catch((err) => {
                console.log(err);
            });
        }
    </script>
</body>

</html>